// pages/EchartsPrints/DDLine/DDLine.js
import * as echarts from '../../../ec-canvas/echarts.js';
const app = getApp();
let pageInstance = {}
var option = {
  
  title: {
    text: '本周新增变化',
    left: 'center'
  },
  color: ["#37A2DA", "#67E0E3", "#9FE6B8"],
  legend: {
    data: ['A市', 'B市', 'C市'],
    top: 50,
    left: 'center',
    backgroundColor: 'red',
    z: 100
  },
  grid: {
    containLabel: true
  },
  tooltip: {
    show: true,
    trigger: 'axis',
  
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    // show: false
  },
  yAxis: {
    x: 'center',
    type: 'value',
    splitLine: {
      lineStyle: {
        type: 'dashed'
      }
    }
    // show: false
  },
  series: [{
    name: 'A市',
    type: 'line',
    smooth: true,
    data: [18, 36, 65, 30, 78, 40, 33]
  }, {
    name: 'B市',
    type: 'line',
    smooth: true,
    data: [12, 50, 51, 35, 70, 30, 20]
  }, {
    name: 'C市',
    type: 'line',
    smooth: true,
    data: [10, 30, 31, 50, 40, 20, 10]
}]
};
function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  

  chart.setOption(option);
  return chart;
}

Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  properties: {
    region:{
      type:String,
      value:'省',
      observer: function(newVal, oldVal) {
        // 属性值变化时执行,更新折线图 写在此部分
        console.log('省份更新为' + newVal)
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    ec: {
      onInit: initChart
    },
  },
  lifetimes: {
    created: function () {
       pageInstance = this;
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {

    echartInit (e) {
      initChart(e.detail.canvas, e.detail.width, e.detail.height);
    }
  }
})
